<#assign pojo=oneToManyPojo.getOne()>
<#assign many=oneToManyPojo.getMany()>
<#assign ones=oneToManyPojo.getOnes()>
package ${pojo.getPackageName()}.service;

<#assign classbody>
<#assign declarationName = pojo.importType(pojo.getDeclarationName())>
/**
 * @author bo.wang
 */
public abstract class Base${declarationName}Service extends BaseMongoDBService{

	public static final String BEAN_ID="${pojo.getDeclarationNameFirstLetterLower()}Service";

	@Resource
	${declarationName}Dao ${pojo.getDeclarationNameFirstLetterLower()}Dao;


	public IMongoDBDao getDao() {
		return ${pojo.getDeclarationNameFirstLetterLower()}Dao;
	}


	public DaoPage find${declarationName}VOByParams(Map params, Integer pageIndex,
			Integer pageSize) {
		if(params==null)
		{
			params=new HashMap();
		}
		DaoPage daoPage= ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${declarationName}ByParams(params, pageIndex, pageSize);
		daoPage.setResult(convert${declarationName}ToVO((List<${declarationName}Entity>) daoPage.getResult()));
		return daoPage;
	}

	public List<${declarationName}VO> find${declarationName}VOByParams(Map params) {
		if(params==null)
		{
			params=new HashMap();
		}
		List<${declarationName}Entity> temp= ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${declarationName}ByParams(params);
		return convert${declarationName}ToVO(temp);
	}

    public DaoPage find${declarationName}ByParams(Map params, Integer pageIndex,
        Integer pageSize) {
        if(params==null)
        {
            params=new HashMap();
        }
        DaoPage daoPage= ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${declarationName}ByParams(params, pageIndex, pageSize);
        return daoPage;
    }

    public List<${declarationName}Entity> find${declarationName}ByParams(Map params) {
        if(params==null)
        {
            params=new HashMap();
        }
        List<${declarationName}Entity> temp= ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${declarationName}ByParams(params);
        return temp;
    }


	public void save${declarationName}DataListsMap(Map dataListsMap) {
		Collection<${declarationName}VO> deleteList = BatchUtils.to(${declarationName}VO.class).getDeleteEntities(dataListsMap);
		Collection<${declarationName}VO> insertList =  BatchUtils.to(${declarationName}VO.class).getInsertEntities(dataListsMap);
		Collection<${declarationName}VO> updateList =  BatchUtils.to(${declarationName}VO.class).getModifiedEntities(dataListsMap);
		if (updateList != null&&updateList.size() > 0) {
			for(${declarationName}VO vo: updateList){
				${declarationName}Entity entity=convert${declarationName}VOToEntity(vo);
				${pojo.getDeclarationNameFirstLetterLower()}Dao.update(entity);
			}
//			${pojo.getDeclarationNameFirstLetterLower()}Dao.updateAll(updateList);
		}
		if (insertList != null&&insertList.size() > 0) {
			for(${declarationName}VO vo: insertList){
				${declarationName}Entity entity=convert${declarationName}VOToEntity(vo);
				${pojo.getDeclarationNameFirstLetterLower()}Dao.save(entity);
				vo.setId(entity.getId());
			}
//			${pojo.getDeclarationNameFirstLetterLower()}Dao.saveAll(insertList);
		}
		if (deleteList != null&&deleteList.size() > 0) {
			for(${declarationName}VO vo:deleteList){
				${declarationName}Entity entity=new ${declarationName}Entity();
				entity.setId(vo.getId());
				${pojo.getDeclarationNameFirstLetterLower()}Dao.remove(entity);
			}
//			${pojo.getDeclarationNameFirstLetterLower()}Dao.removeAll(deleteList);
		}

	}
    protected abstract List<${declarationName}VO> convert${declarationName}ToVO(List<${declarationName}Entity> models);
	public abstract ${declarationName}VO convert${declarationName}ToVO(${declarationName}Entity model);
	public abstract ${declarationName}Entity convert${declarationName}VOToEntity(${declarationName}VO vo);
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
<#assign tempchild=child>

	public DaoPage find${childdeclarationName}VOByParams(Map params, Integer pageIndex,
			Integer pageSize) {
		if(params==null)
		{
			params=new HashMap();
		}
		DaoPage daoPage= ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${childdeclarationName}ByParams(params, pageIndex, pageSize);
		daoPage.setResult(convert${childdeclarationName}ToVO((List<${childdeclarationName}Entity>) daoPage.getResult()));
		return daoPage;
	}

	public List<${childdeclarationName}VO> find${childdeclarationName}VOByParams(Map params) {
		if(params==null)
		{
			params=new HashMap();
		}
		List<${childdeclarationName}Entity> temp= ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${childdeclarationName}ByParams(params);
		return convert${childdeclarationName}ToVO(temp);
	}

    public DaoPage find${childdeclarationName}ByParams(Map params, Integer pageIndex,
        Integer pageSize) {
        if(params==null)
        {
            params=new HashMap();
        }
        DaoPage daoPage= ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${childdeclarationName}ByParams(params, pageIndex, pageSize);
        return daoPage;
    }

    public List<${childdeclarationName}Entity> find${childdeclarationName}ByParams(Map params) {
        if(params==null)
        {
            params=new HashMap();
        }
        return ${pojo.getDeclarationNameFirstLetterLower()}Dao.find${childdeclarationName}ByParams(params);
    }

	public void save${childdeclarationName}DataListsMap(Map dataListsMap) {
		Collection<${childdeclarationName}VO> deleteList = BatchUtils.to(${childdeclarationName}VO.class).getDeleteEntities(dataListsMap);
		Collection<${childdeclarationName}VO> insertList =  BatchUtils.to(${childdeclarationName}VO.class).getInsertEntities(dataListsMap);
		Collection<${childdeclarationName}VO> updateList =  BatchUtils.to(${childdeclarationName}VO.class).getModifiedEntities(dataListsMap);
		if (updateList != null&&updateList.size() > 0) {
			for(${childdeclarationName}VO vo: updateList){
				${childdeclarationName}Entity entity=convert${childdeclarationName}VOToEntity(vo);
				${pojo.getDeclarationNameFirstLetterLower()}Dao.update(entity);
			}
//			${pojo.getDeclarationNameFirstLetterLower()}Dao.updateAll(updateList);
		}
		if (insertList != null&&insertList.size() > 0) {
			for(${childdeclarationName}VO vo: insertList){
				${childdeclarationName}Entity entity=convert${childdeclarationName}VOToEntity(vo);
				${pojo.getDeclarationNameFirstLetterLower()}Dao.save(entity);
				vo.setId(entity.getId());
			}
//			${pojo.getDeclarationNameFirstLetterLower()}Dao.saveAll(insertList);
		}
		if (deleteList != null&&deleteList.size() > 0) {
			for(${childdeclarationName}VO vo:deleteList){
				${childdeclarationName}Entity entity=new ${childdeclarationName}Entity();
				entity.setId(vo.getId());
				${pojo.getDeclarationNameFirstLetterLower()}Dao.remove(entity);
			}
//			${pojo.getDeclarationNameFirstLetterLower()}Dao.removeAll(deleteList);
		}
	}
    protected abstract List<${childdeclarationName}VO> convert${childdeclarationName}ToVO(List<${childdeclarationName}Entity> models);
	public abstract ${childdeclarationName}VO convert${childdeclarationName}ToVO(${childdeclarationName}Entity model);
	public abstract ${childdeclarationName}Entity convert${childdeclarationName}VOToEntity(${childdeclarationName}VO vo);
</#foreach>
<#foreach child in ones>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
	public abstract ${childdeclarationName} find${childdeclarationName}(Map params);
</#foreach>
}
</#assign>
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ling.pl.core.commons.support.DaoPage;
import com.ling.pl.core.commons.utils.AssertHelper;
import com.ling.pl.core.commons.utils.BatchUtils;
import com.ling.pl.core.commons.utils.reflect.ReflectUtils;
import com.ling.pl.core.dao.IMongoDBDao;
import com.ling.pl.core.service.impl.BaseMongoDBService;
import ${pojo.getPackageName()}.model.${declarationName};
import ${pojo.getPackageName()}.model.${declarationName}VO;
import ${pojo.getPackageName()}.model.${declarationName}Entity;
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
import ${child.getPackageName()}.model.${childdeclarationName};
import ${child.getPackageName()}.model.${childdeclarationName}VO;
import ${child.getPackageName()}.model.${childdeclarationName}Entity;
</#foreach>
<#foreach child in ones>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
import ${child.getPackageName()}.model.${childdeclarationName};
import ${child.getPackageName()}.model.${childdeclarationName}VO;
import ${child.getPackageName()}.model.${childdeclarationName}Entity;
</#foreach>
import ${pojo.getPackageName()}.dao.${declarationName}Dao;
import ${pojo.getPackageName()}.service.${declarationName}Service;
${classbody}
